package com.dinggou.shopjb.utils.auth;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build;
import android.view.View;

import com.mobile.auth.gatewayauth.AuthRegisterXmlConfig;
import com.mobile.auth.gatewayauth.AuthUIConfig;
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper;
import com.mobile.auth.gatewayauth.ui.AbstractPnsViewDelegate;
import com.nirvana.tools.core.AppUtils;
import com.dinggou.shopjb.R;
import com.dinggou.shopjb.base.BaseActivity;
import com.dinggou.shopjb.constants.Constant;
import com.dinggou.shopjb.utils.DataUtils;

public class DialogPortConfig extends BaseUIConfig {
    /**
     * 应用包名
     */
    private String mPackageName;
    private BaseActivity mBaseActivity;

    public DialogPortConfig(Activity activity, PhoneNumberAuthHelper authHelper) {
        super(activity, authHelper);
        mPackageName = AppUtils.getPackageName(activity);
        mBaseActivity = (BaseActivity) activity;
    }

    @Override
    public void configAuthPage() {
        mAuthHelper.removeAuthRegisterXmlConfig();
        mAuthHelper.removeAuthRegisterViewConfig();
        int authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
        if (Build.VERSION.SDK_INT == 26) {
            authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
        }
        updateScreenSize(authPageOrientation);
        int dialogWidth = (int) (mScreenWidthDp * 0.84f);
        int dialogHeight = (int) (mScreenHeightDp * 0.5f + 50);
        int unit = dialogHeight / 10;
        int logBtnHeight = (int) (unit * 1.2);

//        mAuthHelper.addAuthRegistViewConfig("switch_msg", new AuthRegisterViewConfig.Builder()
//                .setView(initSwitchView(unit * 5 + 20, Constant.DIALOG_PORT))
//                .setRootViewId(AuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
//                .setCustomInterface(new CustomInterface() {
//                    @Override
//                    public void onClick(Context context) {
//                        mAuthHelper.quitLoginPage();
//                    }
//                })
//                .build());

        mAuthHelper.addAuthRegisterXmlConfig(new AuthRegisterXmlConfig.Builder()
                .setLayout(R.layout.custom_port_dialog_action_bar, new AbstractPnsViewDelegate() {
                    @Override
                    public void onViewCreated(View view) {
                        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mAuthHelper.quitLoginPage();
                            }
                        });

                    }
                })
                .build());

        String clientId = DataUtils.getClientId(mContext);
//        boolean accessPrivacy = false;
//        if(clientId.equals(Constant.TT_CLIENT_ID) || clientId.equals(Constant.HW_CLIENT_ID)){
//            accessPrivacy = DataUtils.getBooleanSPByTag(mContext, DataUtils.SP_ACCESS_AGREEMENT);
//        }

        mAuthHelper.setAuthUIConfig(new AuthUIConfig.Builder()
                //进出场动画
                .setAuthPageActIn("in_activity", "out_activity")
                .setAuthPageActOut("in_activity", "out_activity")
                //方向
                .setScreenOrientation(authPageOrientation)
                //设置宽高
                .setDialogWidth(dialogWidth)
                .setDialogHeight(dialogHeight)
                .setAppPrivacyOne("《用户协议》", Constant.H5_USER_URL)
                .setAppPrivacyTwo("《风险揭示书》",  Constant.H5_RISK_DISCLOSURE)
                .setAppPrivacyThree("《隐私协议》", Constant.H5_PRIVATE_URL)
                //隐私协议颜色
                .setAppPrivacyColor(Color.GRAY, Color.parseColor("#1577FE"))
                //隐私协议是否勾选
                .setPrivacyState(false)
                //导航栏是否隐藏
                .setNavHidden(true)
                //复选框是否隐藏
                .setCheckboxHidden(false)
                //是否是底部弹窗
                .setDialogBottom(false)
                //设置应用包名
                .setPackageName(mPackageName)
//                .setNavColor(Color.TRANSPARENT)
//                .setWebNavColor(ContextCompat.getColor(mContext, R.color.color_477ae5))
                //设置字体大小，以Dp为单位，不同于Sp，不会随着系统字体变化而变化
                .setNumberSizeDp(24)
//                .setLogBtnWidth(dialogWidth - 30)
//                .setLogBtnMarginLeftAndRight(15)
                .setLogBtnTextSizeDp(15)
                .setLogBtnText("本机号码一键登录/注册")
//                .setLogBtnHeight(44)
                //手机号距离上面
                .setNumFieldOffsetY(150)
                //登录按钮距离上面
                .setLogBtnOffsetY(200)
                .setLogBtnBackgroundPath("selector_bg_btn")
                //口号是否隐藏
                .setSloganHidden(true)
                //其他登录方式是否隐藏
                .setSwitchAccHidden(true)
                //运营商前后缀
                .setVendorPrivacyPrefix("《")
                .setVendorPrivacySuffix("》")
                .create());
    }
}
